﻿<%@ Page Title="advertisment" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="crm_advertisment.aspx.cs" Inherits="Sami_SMS_CRM_UI.crm_advertisment" MaintainScrollPositionOnPostback="true" %>

<%@ Register Src="UserControl/ucPaging.ascx" TagName="ucPaging" TagPrefix="uc1" %>
<asp:Content ID="CSS" runat="server" ContentPlaceHolderID="CssContent">
    <style type="text/css">
        .detail{color: #555555; text-decoration:none;}
        .detail:hover{text-decoration:underline;}
        #dialog-form2-content span{display:inline-block; width:200px; margin: 5px; font-weight:bolder;}
    </style>
</asp:Content>
<asp:Content ID="Script" runat="server" ContentPlaceHolderID="ScriptContent">
    <script src="Scripts/jquery.textchange.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            RegisterDialog();
            DateTimePicker("txtStartExpected,txtEndExpected");
            TimePicker("txtSentFrom,txtSentTo");
            
            CountLetter($("#<%=txtMessage.ClientID%>"));
            $("#<%=txtMessage.ClientID%>").bind('textchange', function () {
               CountLetter($(this));
            });
        });

        function CountLetter(obj){
            var str = $(obj).val();
            var letter = str.length;
            var message = 0, letterPermessage = 0;
            if (!ContainsUnicodeCharacter(str)) {
                if (letter <= 160)
                    letterPermessage = 160;
                else
                    letterPermessage = 153;
            }
            else {
                if (letter <= 70)
                    letterPermessage = 70;
                else
                    letterPermessage = 67;
            }
            var message = Math.floor(letter / letterPermessage);
            var div = letter % letterPermessage;
            if (div > 0) message += 1;
            if (message == 0) message = 1;
            $("#lbletter").html(letter);
            $("#lbmessage").html(message);
        } 

        function ContainsUnicodeCharacter(str) {
            for (var i = 0, n = str.length; i < n; i++) {
                if (str.charCodeAt(i) > 127) {
                    return true;
                }
            }
            return false;
        }
        function GetTotalMtQueue(advertisment_id){
            $.ajax({
                    type: "POST",
                    url: "crm_advertisment.aspx/GetTotalMtQueue",
                    data:"{'advertisment_id': " + advertisment_id + "}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $("#dialog-form2-content").html(
                            "<p><span>max advertisment</span>: " + data.d[0] +"</p>" +
                            "<p><span>sent gateway advertisment</span>: " + data.d[1] + "</p>" +
                            "<p><span>sent mt_queue advertisment</span>: " + data.d[2] + "</p>" +
                            "<p><span>sent mt_queue today</span>: " + data.d[3] + "</p>"  
                        );
                        OpenDialog("dialog-form2");
                    }
                });
        }
    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <div class="box">
        <div class="box-title">
            <div class="fl">
                List of CRM_Advertisment
            </div>
            <div class="fr">
                <asp:ImageButton ID="btnAddNew" runat="server" ImageUrl="~/img/icons/ws/ic_plus.png"
                    ToolTip="Add New" OnClick="btnAddNew_Click" />
            </div>
            <div class="clear">
            </div>
        </div>
        <div class="box-content">
            <div class="clearfix" style="height: 32px">
                <div class="fl">
                    Show
                    <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlPageSize_SelectedIndexChanged">
                        <asp:ListItem Value="5">5</asp:ListItem>
                        <asp:ListItem Value="10">10</asp:ListItem>
                        <asp:ListItem Value="20">20</asp:ListItem>
                        <asp:ListItem Value="50" Selected="True">50</asp:ListItem>
                        <asp:ListItem Value="100">100</asp:ListItem>
                        <asp:ListItem Value="150">150</asp:ListItem>
                        <asp:ListItem Value="200">200</asp:ListItem>
                    </asp:DropDownList> / 
                    <asp:Literal ID="ltrTotalRow" runat="server" Text="0" /> 
                    entries
                </div>
                <div class="fr">
                    <uc1:ucPaging ID="pagingtop" runat="server" />
                </div>
            </div>
            <div class="clearfix">
                <table class="table" style="width: 100%;">
                    <thead>
                        <tr>
                            <th style="width: 35px">
                                No
                            </th>
                            <th>
                                Message
                            </th>
                            <th style="width: 60px">
                                Max adv
                            </th>
                            <th style="width: 60px">
                                Sent adv
                            </th>
                            <th style="width: 60px">
                                Sent mt_queue today
                            </th>
                            <th>
                                Sender Name
                            </th>
                            <th>
                                Create By
                            </th>
                            <th>
                                Start expected
                            </th>
                            <th>
                                End expected
                            </th>
                            <th>
                                Allow sent from
                            </th>
                            <th>
                                Allow sent to
                            </th>
                            <th>
                                Action Id
                            </th>
                            <th>
                                Status
                            </th>
                            <th style="width: 80px">
                                Control
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <asp:Repeater ID="rptTable" runat="server" OnItemCommand="rptTable_ItemCommand" 
                            onitemdatabound="rptTable_ItemDataBound">
                            <ItemTemplate>
                                <tr>
                                    <td style="text-align: center">
                                        <%#(Container.ItemIndex +1) + (pagingtop.CurrentPage - 1) * pagingtop.PageSize %>
                                    </td>
                                    <td runat="server" id="td_message">
                                        <a href="crm_advertisment_view.aspx?advid=<%#Eval("advertisment_id")%>" class="detail"><%#Eval("message")%></a>
                                        <asp:HiddenField ID="hdfcollectionid" runat="server" Value='<%#Eval("collection_id")%>' />
                                    </td>
                                    <td><%#Eval("max_advertisment")%></td>
                                    <td><%#Eval("sent_advertisment")%></td>
                                    <td><%#Eval("advsent")%></td>
                                    <td>
                                        <%#Eval("sender_name")%>
                                    </td>
                                    <td>
                                        <%#Eval("create_by")%>
                                    </td>
                                    <td>
                                        <%#Eval("start_expected")%>
                                    </td>
                                    <td>
                                        <%#Eval("end_expected")%>
                                    </td>
                                    <td>
                                        <%#Eval("allow_sent_from")%>
                                    </td>
                                    <td>
                                        <%#Eval("allow_sent_to")%>
                                    </td>
                                    <td runat="server" id="td_action_id">
                                        <asp:Literal ID="ltractionId" runat="server" Text='<%#Eval("action_id")%>' />
                                    </td>
                                    <td>
                                        <%#Eval("status")%>
                                    </td>
                                    <td style="text-align: center">
                                        <asp:LinkButton Text="Edit" runat="server" CommandName="Edited" CommandArgument='<%#Eval("advertisment_id")%>' />
                                        &nbsp;
                                        <asp:LinkButton Text="Delete" runat="server" CommandName="Deleted" CommandArgument='<%#Eval("advertisment_id")%>'
                                            OnClientClick="return confirm('Are you sure delete?');" />
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:Repeater>
                    </tbody>
                </table>
                <div class="fr">
                    <uc1:ucPaging ID="pagingbottom" runat="server" />
                </div>
            </div>
        </div>
    </div>
    <div class="dialog-form" id="dialog-form1" style="margin: auto; width: 480px;" title="CRM Advertisment">
        <div>
            <asp:HiddenField ID="hdfAction" runat="server" />
            <asp:HiddenField ID="hdfAdvId" runat="server" />
            <p>
                <span>Message (<span id="lbletter">0</span> letter / <span id="lbmessage">1</span> message)
                </span>
                <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" autocomplete="off" />
            </p>
            <p>
                <span>sender name</span>
                <asp:DropDownList ID="ddlSenderName" runat="server" />
            </p>
            <p>
                <span>mt flag</span>
                <asp:DropDownList ID="ddlMtFlag" runat="server" />
            </p>
            <p>
                <span>Start Expected</span>
                <asp:TextBox ID="txtStartExpected" runat="server" />
            </p>
            <p>
                <span>End Expected</span>
                <asp:TextBox ID="txtEndExpected" runat="server" />
            </p>
            <p>
                <span>Allow sent from</span>
                <asp:TextBox ID="txtSentFrom" runat="server"/>
            </p>
            <p>
                <span>Allow sent to</span>
                <asp:TextBox ID="txtSentTo" runat="server"/>
            </p>
            <p>
                <span>Action</span>
                <asp:DropDownList ID="ddlAction" runat="server" />
            </p>
            <p>
                <span>Collection</span>
                <asp:DropDownList ID="ddlCollection" runat="server" />
            </p>
            <p>
                <span>Status</span>
                <asp:DropDownList ID="ddlStatus" runat="server" />
            </p>
            <p>
                <span>Max advertisment</span>
                <asp:TextBox ID="txtMaxAdv" runat="server" onkeypress="return ValidateKeypress(/[\d]/,event);" />
            </p>
            <p>
                <span>Sent advertisment</span>
                <asp:TextBox ID="txtSentAdv" runat="server" onkeypress="return ValidateKeypress(/[\d]/,event);"/>
            </p>
            <div style="text-align: right; margin-top: 5px; padding-top: 5px; border-top: 1px solid #C3C3C3;">
                <asp:Button ID="btnOK" runat="server" Text="OK" CssClass="ui-button" OnClick="btnOK_Click" />
                <input type="button" value="Cancel" onclick='$("#dialog-form1").dialog("close");'
                    class="ui-button" />
            </div>
        </div>
    </div>
    <div class="dialog-form" id="dialog-form2" style="margin: auto; width: 480px;" title="message statistics">
        <div id="dialog-form2-content"></div>
    </div>
    <input type="hidden" id="formId" value="crm_advertisment" />
</asp:Content>
